﻿using Newtonsoft.Json;
using SearchServer;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TCP服务器端;

class PTManager
{
    public static void CheckPT(string s)
    {
        string[] s1 = s.Split('|');
       // Console.WriteLine(s1);
        if (s1[0]=="PTransform")
        {
            PTransform ptt= JsonConvert.DeserializeObject<PTransform>(s1[1]);
            s=JsonConvert.SerializeObject(ptt);
        }
        else if (s1[0]== "PTChangeView")
        {
            PTChangeView ptt = JsonConvert.DeserializeObject<PTChangeView>(s1[1]);
            s = JsonConvert.SerializeObject(ptt);

        }
        else if (s1[0]=="PTLogin")
        {
            PTLogin ptt = JsonConvert.DeserializeObject<PTLogin>(s1[1]);
            ptt.clientId = Program.id;
            s = JsonConvert.SerializeObject(ptt);

        }
        else if (s1[0]== "PTPlayerExist")
        {
            PTPlayerExist ptt = JsonConvert.DeserializeObject<PTPlayerExist>(s1[1]);
            s = JsonConvert.SerializeObject(ptt);
            if (Program.id > 1)
            {
                Program.id--;
            }

        }
        else if (s1[0] == "PTGameOver")
        {
            PTGameOver ptt = JsonConvert.DeserializeObject<PTGameOver>(s1[1]);
            s = JsonConvert.SerializeObject(ptt);

            Program.id = 1;
        }
        s = s1[0] +'|'+s;
        if (s1[0]=="PTLogin")
        {
            Program.id++;
        }

        Console.WriteLine(Program.id);
        //Console.WriteLine("广播协议" +s);
        ClientManager.BroadCastToClientSockets(s, s.Length);
    }
}

